package com.hanthink.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hanthink.common.annotation.Log;
import com.hanthink.common.core.controller.BaseController;
import com.hanthink.common.core.domain.AjaxResult;
import com.hanthink.common.enums.BusinessType;
import com.hanthink.system.domain.SysSite;
import com.hanthink.system.service.ISysSiteService;
import com.hanthink.common.utils.poi.ExcelUtil;
import com.hanthink.common.core.page.TableDataInfo;

/**
 * 工厂信息Controller
 * 
 * @author hanthink
 * @date 2021-01-19
 */
@RestController
@RequestMapping("/system/site")
public class SysSiteController extends BaseController
{
    @Autowired
    private ISysSiteService sysSiteService;

    /**
     * 查询工厂信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSite sysSite)
    {
        startPage();
        List<SysSite> list = sysSiteService.selectSysSiteList(sysSite);
        return getDataTable(list);
    }

    /**
     * 导出工厂信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:site:export')")
    @Log(title = "工厂信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysSite sysSite)
    {
        List<SysSite> list = sysSiteService.selectSysSiteList(sysSite);
        ExcelUtil<SysSite> util = new ExcelUtil<SysSite>(SysSite.class);
        return util.exportExcel(list, "site");
    }

    /**
     * 获取工厂信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:query')")
    @GetMapping(value = "/{siteKey}")
    public AjaxResult getInfo(@PathVariable("siteKey") Long siteKey)
    {
        return AjaxResult.success(sysSiteService.selectSysSiteById(siteKey));
    }

    /**
     * 新增工厂信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:add')")
    @Log(title = "工厂信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSite sysSite)
    {
        return toAjax(sysSiteService.insertSysSite(sysSite));
    }

    /**
     * 修改工厂信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:edit')")
    @Log(title = "工厂信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSite sysSite)
    {
        return toAjax(sysSiteService.updateSysSite(sysSite));
    }

    /**
     * 删除工厂信息
     */
    @PreAuthorize("@ss.hasPermi('system:site:remove')")
    @Log(title = "工厂信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{siteKeys}")
    public AjaxResult remove(@PathVariable Long[] siteKeys)
    {
        return toAjax(sysSiteService.deleteSysSiteByIds(siteKeys));
    }
}
